<style>
    .highlight-top {
      background: linear-gradient(135deg, #43d091, #00BCD4);
      background-color: #184e8e;
      margin-top: -15px;
      padding-bottom: 15px;
    }

    .highlight-blue .buttons {
      text-align: center;
    }

    .highlight-blue .buttons .btn-primary, .highlight-blue .buttons .btn-primary:active {
      border: 2px solid rgba(255,255,255,0.7);
      border-radius: 6px;
      color: #ebeff1;
      box-shadow: none;
      text-shadow: none;
      padding: 14px 24px;
      background: transparent;
      transition: background-color 0.25s;
    }

    #startedHolder {
      background: #212529;
    }
</style>

<div class="highlight-blue highlight-top pt-5 pb-5">
    <div class="container-fluid">
        <div class="intro text-light">
            <h2 class="text-center">New? Don&#39;t Know Where To Start?</h2>
            <p class="text-center">Don&#39;t worry! We got you covered! Click below to learn more about cryptocurrency mining, and how you can get started today!</p>
        </div>
        <div class="buttons"><a class="btn btn-primary" role="button" href="/learn_more">Learn More About Mining!</a></div>
    </div>
</div>
<div class="highlight-blue bg-dark pt-3 pb-2">
    <div class="container">
        <div class="intro text-light">
            <h2 class="text-center" style="margin:0 0 25px;">Know What You&#39;re Doing?</h2>
            <p class="text-center">Get started with our pool by using the simple configuration tool we provided below!</p>
        </div>
    </div>
</div>
<div class="container">
  <table class="table table-bordered">
      <thead>
        <tr>
          <th colspan="2"><p class="lead text-center my-0">Miner Configuration Generator</p></th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td><p class="mt-2 mb-0">Coin</p></td>
          <td>
            <select id="coinSelectBox" class="custom-select custom-select-md" style="width:100%;">
              <optgroup label="Available Coins">
                {{for(pool in it.stats.pools) { }}
                 <option value="{{=pool + (it.poolsConfigs[pool].coin.algorithm === 'yescryptR32' ? '_cpu' : '')}}">{{=pool.charAt(0).toUpperCase() + pool.slice(1)}}</option>
                {{ } }}
              </optgroup>
            </select>
          </td>
        </tr>
        <tr>
          <td><p class="mt-2 mb-0">Miner</p></td>
          <td>
            <select id="minerSelectBox" class="custom-select custom-select-md" style="width:100%;">
              <optgroup label="Popular Mining Software">
                <option value="ccminer" selected>CCMiner (Nvidia)</option>
                <option value="sgminer">SGMiner (AMD)</option>
              </optgroup>
            </select>
          </td>
        </tr>
        <tr>
          <td><p class="mt-2 mb-0" data-toggle="tooltip" data-placement="left" title="Optional">Wallet<small><sup>*</sup></small></p></td>
          <td><input id="walletInputBox" class="form-control my-0" type="text" placeholder="Wallet Address" aria-label="Wallet Address" style="width:100%;" /></td>
        </tr>
        <tr>
          <td colspan="2" style="text-align: center;">
            {{ var info = []; }}
            {{ for(var pool in it.poolsConfigs) {
                info.push({
                    coin: it.poolsConfigs[pool].coin,
                    algo: it.poolsConfigs[pool].coin.algorithm,
                    ports: it.poolsConfigs[pool].ports,
                    host: it.portalConfig.website.stratumHost
                });
            }}
            {{ } }}
            {{ info = JSON.stringify(info).replace(/"/g, '&quot;'); }}
            <a id="generateConfig" href="#" data-info="{{=info}}" class="btn btn-dark w-100" type="button">Generate</a>
          </td>
        </tr>
        <tr>
          <td colspan="2" style="text-align: center;">
            <div class="input-group class="my-2"">
              <input id="generatedConfigOutput" type="text" class="form-control" style="text-align:center;" value="Donate: ccminer -a neoscrypt -o stratum+tcp://{{=it.portalConfig.website.stratumHost}}:22000 -u MNs3x26ZGstazVXPTNmPbm6PVRd39Ke8gK -p c=MOG" aria-describedby="basic-addon2" readonly>
              <div class="input-group-append">
                <span class="input-group-text" id="copyButton"><button class="btn btn-info w-100" type="button" data-toggle="popover" data-content="Copied To Clipboard!"><i class="fa fa-clipboard"></i></button></span>
              </div>
            </div>
          </td>
        </tr>
      </tbody>
  </table>
</div>
<script>
  $("[data-toggle=tooltip").tooltip();

  $('#coinSelectBox').on('change', function (e) {
    var optionSelected = $("option:selected", this);
    var valueSelected = this.value;
    console.log(valueSelected);
    if(valueSelected.endsWith('_cpu')){
      $("#minerSelectBox").empty();
      $("#minerSelectBox").append("<option value=\"cpu\">Generic (CPU)</option>");
    } else {
      $("#minerSelectBox").empty();
      $("#minerSelectBox").append("<option value=\"sgminer\">SGMiner (AMD)</option>");
      $("#minerSelectBox").append("<option value=\"ccminer\" selected>CCMiner (Nvidia)</option>");
    }
});

  $('#generateConfig').click(function(event){
      event.preventDefault();
      generate($(this).data('info'));
      return false;
  });

  $('#copyButton').click(function(event){
      event.preventDefault();
      copyToClipboard();
      return false;
  });

  var generate =  function(info) {
    var raw = "{0} -{5} {1} -o stratum+tcp://{{=it.portalConfig.website.stratumHost}}:{2} -u {3} -p c={4}";
    var miner = $('#minerSelectBox').val();
    var coin = $('#coinSelectBox').val().replace('_cpu', '');
    console.log(coin);
    var wallet = $('#walletInputBox').val() || "<WALLET_ADDRESS>";
    var coinData = info.filter(x => x.coin.name === coin)[0];
    if(coinData){
      var symbol = coinData.coin.symbol;
      var algo = coinData.algo;
      var port = Object.keys(coinData.ports)[0];
      $('#generatedConfigOutput').val(raw.format(miner, algo, port, wallet, symbol, miner.startsWith('sg') ? 'k' : 'a'));
    } else {
      $('#generatedConfigOutput').val("Something Went Wrong! Could Not Generate Configuration!");
    }
  };

  function copyToClipboard() {
    var $temp = $("<input>");
    $("body").append($temp);
    $temp.val($('#generatedConfigOutput').val()).select();
    document.execCommand("copy");
    $temp.remove();
  }

    function showCoinConfig(info){

        var htmlKeys = '<div class="coinInfoData">Algorithm:</div>';
        var htmlValues = '<div class="coinInfoData">' + info.algo + '</div>';

        for (var port in info.ports){
            htmlKeys += '<div class="coinInfoData">URL <span class="coinInfoSubtle">(difficulty ' + info.ports[port].diff + ')</span>:</div>';
            htmlValues += '<div class="coinInfoData">stratum+tcp://' + info.host + ':' + port + '</div>';
        }

        if (info.coin)
            $('#coinInfoUsername').text('your ' + info.coin.name + ' wallet address');
        else
            $('#coinInfoUsername').text('your public key');
        $('.coinInfoData').remove();
        $('#coinInfoRowKeys').append(htmlKeys);
        $('#coinInfoRowValues').append(htmlValues);
    }

    $('#coinGlowTrigger').click(function(event){
        event.preventDefault();
        $('.menuList').addClass('glow');
        setTimeout(function(){
            $('.menuList').removeClass('glow');
        }, 200);
        return false;
    });

    $('.poolOption').click(function(event){
        event.preventDefault();
        showCoinConfig($(this).data('info'));
        $('#coinInfoBackground,#coinInfo').removeClass('hidden');
        $('#coinInfoBackground').css('opacity', 0.7);
        return false;
    });

    $('#coinInfoBackground,#coinInfoClose').click(function(event){
        event.preventDefault();
        $('#coinInfoBackground,#coinInfo').addClass('hidden');
        $('#coinInfoBackground').css('opacity', 0.0);
        return false;
    });

    $('#nompAppDownload').click(function(event){
        event.preventDefault();
        alert('NOMP App development still in progress...');
        return false;
    });

    String.prototype.format = function () {
        var args = [].slice.call(arguments);
        return this.replace(/(\{\d+\})/g, function (a){
            return args[+(a.substr(1,a.length-2))||0];
        });
    };
</script>
